let id;
let app = getApp();
let url = app.globalData.url;
let Price;
let shop_img;
let all_money
let storeId;
let userId;
let merchantId;
let shop_num;
let dishName;
let unit;
let dishCategoryId;
let ordernum;
let resultCod;
let msg;
let caterOrderId;
let src;
let receiver;
let receiverAddress;
let receiverPhone;
let phone;
Page({
    data: {
        quan: [],
        color:"",
        couponCode_text:""
    },
    onLoad(options) {
        phone=""
        var that = this;
        id = options.shop_id;
        that.shopList()
    },
    shopList() {
        var that = this;
        wx.getStorage({
            key: 'userId',
            success: function (res) {
                var userId = res.data.userId;
        wx.request({
            url: url + '/foreignDishCoupon/geDishCoupontDetail.do',
            method: 'get',
            data: {
                id: id,
                userId: userId
            },
            headers: {
                'Content-Type': 'application/json;charset=UTF-8',
                'Accept': 'application/json',
            },
            dataType: 'json',
            success: function (res) {
                console.log(res)
                phone = res.data.body.merchantTel
                if (res.data.body.status==1){
                    var code = JSON.stringify(res.data.body.id)
                    // 12位数字每一位
                    var code1 = code.slice(0, 4)
                    var code2 = code.slice(4, 8)
                    var code3 = code.slice(8, 12)
                    console.log(code)
                    var type=""
                    if (res.data.body.type==1){
                        type ="营销获取"
                    }else if (res.data.body.type == 2) {
                        type = "积分兑换"
                    } else if (res.data.body.type == 3) {
                        type = "商品购买"
                    }
                    // 截取券码：
                    that.setData({
                        dishPic: res.data.body.dishPic,
                        couponName: res.data.body.couponName,
                        couponRemark: res.data.body.couponRemark,
                        dishPrice: res.data.body.dishPrice,
                        couponTimeEnd: res.data.body.couponTimeEnd,
                        code1: code1,
                        code2: code2,
                        code3: code3,
                        couponCode: res.data.body.couponCode,
                        merchantName: res.data.body.merchantName,
                        merchantTel: res.data.body.merchantTel,
                        status:"未使用",
                        color:"#ff7950",
                        type: type,
                        couponCode_text:"向商家展示以上券码即可领取",
                        width:"150px",
                        height:"150px"
                    })
                } else if (res.data.body.status == 2){
                    var code = JSON.stringify(res.data.body.id)
                    // 12位数字每一位
                    var code1 = code.slice(0, 4)
                    var code2 = code.slice(4, 8)
                    var code3 = code.slice(8, 12)
                    console.log(code)
                    var type = ""
                    if (res.data.body.type == 1) {
                        type = "营销获取"
                    } else if (res.data.body.type == 2) {
                        type = "积分兑换"
                    } else if (res.data.body.type == 3) {
                        type = "商品购买"
                    }
                    // 截取券码：
                    that.setData({
                        dishPic: res.data.body.dishPic,
                        couponName: res.data.body.couponName,
                        couponRemark: res.data.body.couponRemark,
                        dishPrice: res.data.body.dishPrice,
                        couponTimeEnd: res.data.body.couponTimeEnd,
                        couponCode:"../images/shiyong.png",
                        code1: code1,
                        code2: code2,
                        code3: code3,
                        merchantName: res.data.body.merchantName,
                        merchantTel: res.data.body.merchantTel,
                        status: "已使用",
                        color: "#aeaeae",
                        type: type,
                        couponCode_text: "领过了，赶紧再领一个",
                        width: "150px",
                        height: "150px"
                    })
                }

               
              
            },
            fail: function (res) {
                // my.alert({
                //   content: res,
                // });
            },
            complete: function (res) {
                wx.hideLoading();
            }
        });
            }
        })
    },
    phone(){
        wx.makePhoneCall({
            phoneNumber: phone
        })
    },
    onPullDownRefresh() {
        var that = this;
        that.shopList();
        wx.stopPullDownRefresh()
    },
});
